home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 5 < prev    next >
Encoding:
Text File  |  1996-08-06  |  3.8 KB  |  119 lines

  1. Path: in1.uu.net!bounce-back
  2. Date: 04 Jan 96 14:16:19 GMT
  3. Approved: fjh@cs.mu.oz.au
  4. X-Original-Date: 04 Jan 96 14:01:51 GMT
  5. Organization: -
  6. Newsgroups: comp.std.c++
  7. Message-ID: <fjh-960105-011629@cs.mu.oz.au>
  8. Cc: warnerd@pascal.dartmouth.edu, bug-g++@prep.ai.mit.edu,
  9.         std-c++@ncar.ucar.edu, jason@cygnus.com
  10. Subject: Re: implicitly declared default constructor isn't generated 
  11. In-Reply-To: Your message of "Thu, 04 Jan 1996 15:06:09 +1100."
  12.              <0kup8l3_3gX_0UIUo0@iassf.easams.com.au> 
  13. X-Original-Date: Wed, 03 Jan 1996 21:29:57 -0800
  14. From: Jason Merrill <jason@cygnus.com>
  15. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  16.     iQBFAgUBMOvhXOEDnX0m9pzZAQGjuwGAiWjHFTt644SP2gUuEh6QIJyObzma8Beq
  17.     XsuLQZ4yHBNNFcxHuHP3PgKIAS4ErnYA
  18.     =IHLm
  19.  
  20. [ Moderator's note: this thread originated from gnu.g++.bug.    ]
  21. [ To fill you in on the missing context, the question at hand   ]
  22. [ is whether or not the code fragment                ]
  23. [                                ]
  24. [    struct Int {                        ]
  25. [        Int( int x ) : x( x ) {}            ]
  26. [        int x;                        ]
  27. [    };                            ]
  28. [                                ]
  29. [    int main() {                        ]
  30. [        Int* pi( new Int[ 2 ] );            ]
  31. [        delete pi;                    ]
  32. [        return 0;                    ]
  33. [    }                            ]
  34. [                                ]
  35. [ is well-formed.    -fjh.                    ]
  36.  
  37. >>>>> Rohan LENARD <rjl@iassf.easams.com.au> writes:
  38.  
  39. > This looks like a hang-over from the ARM, which explicitely stated that
  40. > array of objects will be created by calling all the default ctors.  The
  41. > April draft working paper seems to allow this -
  42.  
  43. > #include <stdio.h>
  44.  
  45. > struct Int
  46. >           {
  47. >               Int( int x ) : x( x ) {
  48. >    fprintf(stderr,"X = %d\n",x);
  49. >   }
  50. >               int x;
  51. >           };
  52. >           int
  53. >           main()
  54. >           {
  55. >               Int* pi = new Int[ 2 ](3);    // Initialise all elements with
  56. > ctor called with (3).
  57. >               delete pi;
  58. >               return 0;
  59. >           }
  60.  
  61. Nope; that does not fall into any of the well-formed cases, since Int[2] is
  62. not a class type.
  63.  
  64. >> Quite right, I read the draft working paper too quickly.  From my
  65. >> point of view though, it should still compile.  According to section
  66. >> 5.3.4 [expr.new] verse 14, the object created by the expression `new
  67. >> Int[ 2 ]' has indeterminate value, which I took to mean the default
  68. >> constructor isn't called, while `new Int[ 2 ]()' does invoke the
  69. >> default constructor.  Is that not a reasonable interpretation?
  70.  
  71. Nope; Int[2] is an array of non-POD class type, so it falls under item 1
  72. of 5.3.4p14.
  73.  
  74. >> Here's the code snippet again:
  75.  
  76. >> struct Int
  77. >> {
  78. >> Int( int x ) : x( x ) {}
  79. >> int x;
  80. >> };
  81.  
  82. >> int
  83. >> main()
  84. >> {
  85. >> Int* pi( new Int[ 2 ] );
  86. >> delete pi;
  87.  
  88. >> return 0;
  89. >> }
  90.  
  91. 14If the type of the object created by the new-expression is T:
  92.  
  93.   --If  the  new-initializer  is  omitted  and T is a non-POD class type
  94.     (_class_) (or array thereof), then if the default constructor for  T
  95.     is accessible it is called, otherwise the program is ill-formed;
  96.  
  97.   --If   the   new-initializer   is   omitted   and  T  is  a  POD  type
  98.     (_basic.types_), then the  object  thus  created  has  indeterminate
  99.     value;
  100.  
  101.   --If  the  new-initializer  is  of the form (), default-initialization
  102.     shall be performed (_dcl.init_);
  103.  
  104.   --If the new-initializer is of the form expression-list) and  T  is  a
  105.     class type, the appropriate constructor is called, using expression-
  106.     list as the arguments (_dcl.init_);
  107.  
  108.   --If the new-initializer is of the form expression-list) and T  is  an
  109.     arithmetic,  enumeration,  pointer,  or  pointer-to-member  type and
  110.     expression-list comprises exactly one expression, then the object is
  111.     initialized  to  the  (possibly  converted)  value of the expression
  112.     (_dcl.init_);
  113.  
  114.   --Otherwise the new-expression is ill-formed.
  115. ---
  116. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  117.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  118.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  119.